import {
  GetTestApi,
  GetHomeBanners,
  GetRecommendNewSongs,
  GetRecommendDaySongs,
  GetTopList,
  GetAlbumList,
  // GetDtHotList,
  GetPlayList,
  GetMvHotList,
  GetSingerHotList,
} from "apis/index";
import { convertUnit } from "utils/index";
import { appInfo } from "config/index";
const app = getApp();
Page({
  data: {
    appInfo,
    fixed: false,
    loading: true,
    banners: [],
    recommendList: [],
    orderList: [],
    everyoneList: [],
    albumList: [],
    // dtList: [],
    mvList: [],
    singerList: [],
    userInfo: null,
  },
  onLoad(options) {
    this.initPage();
  },
  onPageScroll(e) {
    const sTop = convertUnit(e.scrollTop, "pxToRpx");
    this.setData({
      fixed: sTop >= 60,
    });
  },
  onShow() {
    this.setData({
      userInfo: app.globalData.userInfo,
    });
  },
  onPullDownRefresh() {
    this.initPage();
  },
  onShareAppMessage() {},
  //初始化页面数据
  initPage() {
    this.setData({
      loading: true,
    });
    Promise.all([
      this.getBanners(),
      this.getRecommendList(),
      this.getOrderList(),
      this.getAlbumList(),
      // this.getDtList(),
      this.getPlayList(),
      this.getMvList(),
      this.getSingerList(),
      this.getEveryoneList(),
    ]).finally(() => {
      wx.stopPullDownRefresh();
      this.setData({
        loading: false,
      });
    });
  },
  //获取banners图片
  getBanners() {
    GetHomeBanners({ type: 1 }).then((res) => {
      this.setData({
        banners: res.banners,
      });
    });
  },
  //获取推荐歌单列表
  getRecommendList() {
    GetRecommendNewSongs({ limit: 3 }).then((res) => {
      this.setData({
        recommendList: res,
      });
    });
  },
  //获取榜单歌单列表
  getOrderList() {
    GetTopList().then((res) => {
      this.setData({
        orderList: res.list,
      });
    });
  },
  //获取专辑列表
  getAlbumList() {
    GetAlbumList({ limit: 10 }).then((res) => {
      this.setData({
        albumList: res.products,
      });
    });
  },
  //获取电台列表
  // getDtList() {
  //   GetDtHotList({ limit: 10 }).then((res) => {
  //     this.setData({
  //       dtList: res.djRadios,
  //     });
  //   });
  // },
  //获取电台列表
  getPlayList() {
    GetPlayList({ limit: 10 }).then((res) => {
      this.setData({
        playList: res,
      });
    });
  },
  //获取Move列表
  getMvList() {
    GetMvHotList({ limit: 10 }).then((res) => {
      this.setData({
        mvList: res || [],
      });
    });
  },
  //获取热门歌手列表
  getSingerList() {
    GetSingerHotList({ limit: 10 }).then((res) => {
      this.setData({
        singerList: res.artists || [],
      });
    });
  },

  //获取大家都在听歌单列表
  getEveryoneList() {
    // GetRecommendDaySongs 此接口需要登录
    GetTestApi().then((res) => {
      this.setData({
        everyoneList: ["", "", "", "", ""],
      });
    });
  },
});
